#!/bin/bash
import smtplib
from email.mime.text import MIMEText
senderMail = '1842087051@qq.com'
authCode = 'pbuxjhtpvgglbgcb'
receiverMail = '2711526258@qq.com'
subject = '简单邮件'
content = 'hello python'
msg = MIMEText(content,'plain','utf-8')
msg['Subject'] = subject
msg['From'] = senderMail
msg['To'] = receiverMail
try:
    server = smtplib.SMTP_SSL('smtp.qq.com', smtplib.SMTP_SSL_PORT)
    print('成功连接到邮件服务器')
    server.login(senderMail, authCode)
    print('成功登录邮箱')
    server.sendmail(senderMail, receiverMail, msg.as_string())
    print('邮件发送成功')
except smtplib.SMTPException as e:
    print('邮件发送异常')
finally:
    server.quit()


############################################################################

#!/bin/bash
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
senderMail = '1842087051@qq.com'
authCode = 'pbuxjhtpvgglbgcb'
receiverMail = '2711526258@qq.com'
subject = '发给勃勃的测试邮件'
msgRoot = MIMEMultipart('related')
msgRoot['Subjecce'] = subject
msgRoot['Subject'] = subject
msgRoot['From'] = senderMail
msgRoot['To'] = receiverMail
msgAtv = MIMEMultipart('alternative')
msgRoot.attach(msgAtv)
html_content = '''
<p>我的git地址：</p>
<p><a href='https://gitee.com/git_zhangshun/projects'>点击进入我的git</a></p>
<p>我的桌面图片：</p>
<p><img src="cid:image"></p>
'''
html = MIMEText(html_content,'html','utf-8')
msgAtv.attach(html)
f = open('E:\py\qrcode.jpg','rb')
msgImage = MIMEImage(f.read())
f.close()
msgImage.add_header('Content-ID','<image>')
msgRoot.attach(msgImage)
#附件
annex = MIMEText(open('E:\py\ceshi.txt','rb').read(),'base64','utf-8')
annex['Content-Type'] = 'application/octet-stream'
annex['Content-Disposition'] = 'attachement;filename="ceshi.txt"'
msgRoot.attach(annex)
try:
    server = smtplib.SMTP_SSL('smtp.qq.com', smtplib.SMTP_SSL_PORT)
    print('成功连接到邮件服务器')
    server.login(senderMail, authCode)
    print('成功登录邮箱')
    server.sendmail(senderMail, receiverMail, msgRoot.as_string())
    print('邮件发送成功')
except smtplib.SMTPException as e:
    print('邮件发送异常')
finally:
    server.quit()